Repository navigation
perf(io): parallel order-preserving BGZF compression for BAM output - #276
Open
BenjaminDEMAILLE wants to merge 2 commits into
Open
BenjaminDEMAILLE wants to merge 2 commits into
BenjaminDEMAILLE wants to merge 2 commits into
Conversation
New BgzfWriter: the caller fills 64 KiB blocks, --runThreadN dedicated threads compress them with libdeflate, and one writer thread emits them in submission order. Output is byte-identical to noodles_bgzf at every thread count. All four BAM writers use it. finish() now writes the EOF marker and propagates errors instead of relying on drop. Refs #223 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 29, 2026
19 of 23 tasks
Merge of origin/main into #276: only src/io/bam.rs conflicted (main's CoordinateSorter external sort vs #276's BgzfWriter). Resolved by taking main's bam.rs and re-applying #276: make_bgzf_writer(inner, level, threads) -> BgzfWriter, bgzf_threads(params), threads threaded through BamWriter/BamStdoutWriter/CoordinateSorter (spill runs and reduce passes also compress in parallel), finish via get_mut().finish(). Sort semantics, tie order and memory bound are main's; public API shape of #276 unchanged (BamWriter::with_header gains threads). Verified (yeast 200k pairs, 8 threads): samtools view bodies identical to a main build for BAM Unsorted, SortedByCoordinate, and SortedByCoordinate --limitBAMsortRAM 1000000 (spills). cargo fmt, clippy -D warnings, test --release pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenjaminDEMAILLE
added a commit
that referenced
this pull request
Oct 9, 2026
…l-record-encoding Merge of origin/perf/parallel-bgzf-writer (#276: main's external CoordinateSorter + parallel BGZF) into #278 (worker-side SAM/BAM encoding). Conflicts: src/io/bam.rs (7), src/io/sam.rs (1), src/lib.rs (2). sam.rs: kept #276's Default-based BufferedSamRecords::new with #278's encoded fields. bam.rs: CoordinateSorter now buffers BAM-encoded bytes + (ref,pos,off,len) index (replaces #278's SortBuffer and the RecordBuf buffer), spills sorted runs as headerless BGZF of raw records, k-way merges raw records (ties: input order via stable sort + run index). Budget counts real bytes + index entries (estimated_record_bytes removed; its test replaced). SortedBam(Stdout)Writer keep encoder()/write_encoded(). lib.rs: main now builds WithinBAM records on the worker into buf.records, so #278's writer-side supplementary writes and PreEncoder.within_bam were dropped. Verified: fmt, clippy -D warnings, cargo test --release pass; yeast sidx 200k pairs, 8 threads: SAM / BAM Unsorted / Sorted / Sorted+limitBAMsortRAM 1000000 samtools-view bodies md5-identical to a build of origin/perf/parallel-bgzf-writer (with and without RUSTAR_PRE_ENCODE=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #223 (option 1: parallel compression; record encoding still single-threaded).
src/io/bgzf_writer.rs: blocks are filled by the caller, compressed by--runThreadNdedicated threads (not rayon), and written in order by one thread.--runThreadN 1runs inline as before.noodles_bgzf::io::Writer: same block boundaries, libdeflate at the same level, same headers/trailers/EOF. Unit tests compare byte for byte across sizes, levels 0/1/6/12, 1/2/5 threads, irregular writes and flushes;cmpon real runs matched for BAM Unsorted, SortedByCoordinate and SAM.finish()previously called a no-op and relied on drop to write the EOF marker, discarding errors. It now writes EOF, flushes and returns errors.lib.rs,Cargo.tomlor input decoding, so it is independent of perf(align): cut the align batch size and stop cloning every FASTQ record #222, perf(pipeline): size alignment batches so the result vector stays off the arena path #261, feat(io): optional pure-Rust parallel gzip input decoding (rapidgzip-core) #225, chore(deps): bump noodles 0.113 -> 0.115, noodles-bgzf 0.49 -> 0.51 #211, chore(deps): bump noodles from 0.113.0 to 0.116.0 #259.Wall time, 2M SE 100 bp reads, synthetic 20 Mb genome, BAM Unsorted, 16-core Mac (median of 3):
At 16 threads with
--outBAMcompression 6: 5.00s → 2.92s.Follow-up (not here): move BAM record encoding into the parallel align stage (conflicts with #222/#261), and
bam_dedup.rs's own writer.Tests: fmt, clippy 0 warnings,
cargo test636 passed.🤖 Generated with Claude Code